package com.cn.qgx428.lazydiary.anim.viewPager

import android.support.v4.view.ViewPager
import android.view.View

/**
 * Created by QinX on 2017/12/15.
 */
class DepthPageTransformer : ViewPager.PageTransformer {

    companion object {
        val MIN_SCALE = 0.75F
    }

    override fun transformPage(page: View, position: Float) {
        val pageWidth = page?.width

        if (position<-1){
            page?.alpha = 0f
        } else if (position<=0){
            page?.alpha = 1f
            page?.translationX = 0f
            page?.scaleX = 1f
            page?.scaleY = 1f
        } else if (position<=1){
            page?.alpha = 1 - position
            page?.translationX = pageWidth!! * -position
            var scaleFactor = MIN_SCALE
                    + (1 - MIN_SCALE) * (1 - Math.abs(position));
            page?.scaleX = scaleFactor
            page?.scaleY = scaleFactor
        } else{
            page?.alpha = 0f
        }
    }
}